package cn.cloudtogo.common.model;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;

/**
 * @author yaolianhua789@gmail.com
 **/
public class ApiTokenRowMapper implements RowMapper<ApiTokenModel> {

    @Override
    public ApiTokenModel mapRow(ResultSet rs, int rowNum) throws SQLException {
        ApiTokenModel tm = new ApiTokenModel();

        tm.setId(Integer.parseInt(rs.getString("id")));
        tm.setUuid(rs.getString("_uuid"));
        tm.setNotes(rs.getString("notes"));
        tm.setDisable(rs.getBoolean("disable"));
        tm.setType(rs.getString("type"));
        tm.setJson(rs.getString("_json"));
        tm.setToken(rs.getString("token"));
        Timestamp createdAt = rs.getTimestamp("created_at");
        tm.setCreatedAt(createdAt == null ? null : createdAt.toLocalDateTime());

        return tm;
    }
}
